package jqgridjavawrapper;

/**
 * @author Isuru Madushanka Weerarathna
 * @contact uisurumadushanka89@gmail.com
 */
public class JQGridSubGridOptions implements JQPropertyMaker {

    private String iconPlus = null;
    private String iconMinus = null;
    private String iconOpen = null;
    private boolean expandOnLoad = false;
    private boolean selectOnExpand = false;
    private boolean reloadOnExpand = true;

    public StringBuilder generateProperties() {
        StringBuilder sb = new StringBuilder();

        if (iconMinus!=null) sb.append("\nminusicon: ").append(iconMinus).append(',');
        if (iconPlus!=null) sb.append("\nplusicon: ").append(iconPlus).append(',');
        if (iconOpen!=null) sb.append("\nopenicon: ").append(iconOpen).append(',');
        if (expandOnLoad) sb.append("\nexpandOnLoad: ").append(expandOnLoad).append(',');
        if (selectOnExpand) sb.append("\nselectOnExpand: ").append(selectOnExpand).append(',');
        if (!reloadOnExpand) sb.append("\nreloadOnExpand: ").append(reloadOnExpand).append(',');

        if (sb.length() <= 0) {
            return sb;
        }
        sb = new StringBuilder(sb.substring(0, sb.length()-1));
        sb.insert(0, "subGridOptions: {");
        sb.append('}');

        return sb;
    }

    private String formatBool(boolean value) {
        return (value ? "true" : "false");
    }

    private String formatStr(String value) {
        return "\"" + value + "\"";
    }

}
